package com.lfc.myframe.utils

import android.app.Activity
import android.content.Context
import android.content.res.Configuration
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Point
import android.graphics.Typeface
import android.os.Build
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.TextUtils
import android.text.style.AbsoluteSizeSpan
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import android.view.WindowManager
import android.widget.EditText
import android.widget.TextView
import androidx.recyclerview.widget.LinearSnapHelper
import androidx.recyclerview.widget.RecyclerView
import com.flyco.animation.BounceEnter.BounceEnter
import com.flyco.animation.SlideExit.SlideBottomExit
import com.flyco.dialog.listener.OnBtnClickL
import com.flyco.dialog.widget.MaterialDialog
import com.flyco.dialog.widget.NormalDialog
import com.google.gson.GsonBuilder
import com.lfc.myframe.R
import com.lfc.myframe.share.SP_Params
import com.lfc.myframe.ui.login.LoginA
import com.tamsiree.rxkit.RxDeviceTool.callPhone
import java.io.UnsupportedEncodingException
import java.math.BigDecimal
import java.text.DecimalFormat
import java.util.*
import java.util.regex.Pattern

/**
 * Created by LFC
on 2020/5/15.
 */
object LUtils {

    /**
     * 是否是暗黑模式
     */
    fun isDarkTheme(context: Context): Boolean {
        val flag = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
        return flag == Configuration.UI_MODE_NIGHT_YES
    }

    /**
     * 隐藏电话号中间 四位数字
     *
     * @param str_tel
     * @return
     */
    fun HideTel(str_tel: String): String? {
        var str_result: String? = ""
        if (TextUtils.isEmpty(str_tel)) {
            return ""
        }
        if (str_tel.length != 11) {
            return str_tel
        }
        val str_midtel = str_tel.substring(3, 8)
        str_result = str_tel.replace(str_midtel, "*****")
        return str_result
    }

    /**
     * @param mobile
     * @return true 手机号合法  false  手机号不合法
     */
    fun isMobileNumber(mobile: String): Boolean {
        return !TextUtils.isEmpty(mobile) && mobile.length == 11
    }

    /**
     * 计算经纬度之间的距离
     *
     * @param longitude1
     * @param latitude1
     * @param longitude2
     * @param latitude2
     * @return 米
     */
    private const val EARTH_RADIUS = 6378137.0

    fun getDistance(
        longitude1: Double, latitude1: Double,
        longitude2: Double, latitude2: Double
    ): Double {
        val Lat1 = rad(latitude1)
        val Lat2 = rad(latitude2)
        val a = Lat1 - Lat2
        val b = rad(longitude1) - rad(longitude2)
        var s = 2 * Math.asin(
            Math.sqrt(
                Math.pow(Math.sin(a / 2), 2.0)
                        + (Math.cos(Lat1) * Math.cos(Lat2)
                        * Math.pow(Math.sin(b / 2), 2.0))
            )
        )
        s = s * EARTH_RADIUS
        s = Math.round(s * 10000) / 10000.toDouble()
        return s
    }

    private fun rad(d: Double): Double {
        return d * Math.PI / 180.0
    }


    /**
     * 第二种方法
     */
    fun getRandomString2(): String? {
        return getRandomString2(30)
    }

    /**
     * 第二种方法
     */
    fun getRandomString2(allsize: Int): String? {
        var length = 0
        length = if (allsize == 0) {
            Random().nextInt(10) + 5
        } else allsize
        //产生随机数
        val random = Random()
        val sb = StringBuffer()
        //循环length次
        for (i in 0 until length) { //产生0-2个随机数，既与a-z，A-Z，0-9三种可能
            val number = random.nextInt(3)
            var result: Long = 0
            when (number) {
                0 -> {
                    //产生A-Z的ASCII码
                    result = Math.round(Math.random() * 25 + 65)
                    //将ASCII码转换成字符
                    sb.append(result as Char)
                }
                1 -> {
                    //产生a-z的ASCII码
                    result = Math.round(Math.random() * 25 + 97)
                    sb.append(result as Char)
                }
                2 ->  //产生0-9的数字
                    sb.append(Random().nextInt(10).toString())
            }
        }
        return sb.toString()
    }


    /**
     *      * 获取随机汉字
     *      * @return
     *     
     */
    fun getRandomWord(): String? {
        var str = ""
        val heightPos: Int
        val lowPos: Int
        val rd = Random()
        heightPos = 176 + Math.abs(rd.nextInt(39))
        lowPos = 161 + Math.abs(rd.nextInt(93))
        val bt = ByteArray(2)
        bt[0] = Integer.valueOf(heightPos).toByte()
        bt[1] = Integer.valueOf(lowPos).toByte()
        try {
//            str = String(bt, "GBK")
            str = String(bt)
        } catch (e: UnsupportedEncodingException) { // TODO Auto-generated catch block
        }
        return str
    }

    /**
     * @param context
     * @return true 登录  false  未登录
     */
    fun JudgeUserLogin(context: Context?): Boolean {
        val str_token = PreferencesUtils.getString(context, SP_Params.Token)
        //        String str_id = PreferencesUtils.getString(context, Params.UserID);
        return !TextUtils.isEmpty(str_token)
    }

    /**
     *   包含提示框
     */
    fun IsUserLogin(context: Context?): Boolean {
        val str_token = PreferencesUtils.getString(context, SP_Params.Token)
        //        String str_id = PreferencesUtils.getString(context, Params.UserID);
        return if (TextUtils.isEmpty(str_token)) { //未登录
            LUtils.showLoginDialog(context)
            false
        } else {
            true
        }
    }

    open fun showLoginDialog(context: Context?) {
        val materialDialog: MaterialDialog? = MaterialDialog(context)
        materialDialog?.content(context?.getString(R.string.AlartNoLogin))
            ?.title(context?.getString(R.string.DialogTitle))
            ?.btnText(context?.getString(R.string.ignoreNote), context?.getString(R.string.Login))
            ?.btnTextColor(
                context?.resources!!.getColor(R.color.text6),
                context?.resources!!.getColor(R.color.blue)
            )
            ?.showAnim(BounceEnter())
            ?.show()
        materialDialog?.setOnBtnClickL(
            object : OnBtnClickL {
                //left btn click listener
                override fun onBtnClick() {
                    materialDialog.dismiss()
                }
            },
            object : OnBtnClickL {
                //right btn click listener
                override open fun onBtnClick() {
                    materialDialog.dismiss()
                    LoginA.EnterThis(context!!, "", 1)
                }
            }
        )
    }
    //    public void saveBitmapFile(Bitmap bitmap) {
////        File file = new File(e);//将要保存图片的路径
//        File file = new File("mnt/sdcard/uututorstudent" + File.separator + "uututor_logo.jpg");
//        try {
//            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
//            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
//            bos.flush();
//            bos.close();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
    /**
     * 实体类  z转换为 json 字符
     *
     * @return
     */
    fun Beans2Json(obj: Any?, cls: Class<*>?): String? {
        var str_json = ""
        //        if (obj == null) {
//            obj = cls;
//        }
        str_json = try {
            val builder = GsonBuilder()
            val gson = builder.create()
            gson.toJson(obj, cls)
        } catch (e: Exception) {
            ""
        }
        return str_json
    }

    /**
     * 设置删除线
     *
     * @param tv
     */
    fun setDelLine(tv: TextView) { //        tv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线
        tv.paint.flags = Paint.UNDERLINE_TEXT_FLAG //中间横线
        tv.paint.isAntiAlias = true // 抗锯齿
    }

    /**
     * 千位分隔符,并且小数点后保留2位
     *
     * @param num
     * @return String
     */
    fun MoneySplit(num: Double): String? {
        val df = DecimalFormat("#,##0.000")
        return df.format(num)
    }

    /**
     * 坐标转换
     */
    fun bdToGaoDe(bd_lat: Double, bd_lon: Double): DoubleArray? {
        val gd_lat_lon = DoubleArray(2)
        val PI = 3.14159265358979324 * 3000.0 / 180.0
        val x = bd_lon - 0.0065
        val y = bd_lat - 0.006
        val z =
            Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * PI)
        val theta =
            Math.atan2(y, x) - 0.000003 * Math.cos(x * PI)
        gd_lat_lon[0] = z * Math.cos(theta)
        gd_lat_lon[1] = z * Math.sin(theta)
        return gd_lat_lon
    }

    fun gaoDeToBaidu(gd_lon: Double, gd_lat: Double): DoubleArray? {
        val bd_lat_lon = DoubleArray(2)
        val PI = 3.14159265358979324 * 3000.0 / 180.0
        val z =
            Math.sqrt(gd_lon * gd_lon + gd_lat * gd_lat) + 0.00002 * Math.sin(gd_lat * PI)
        val theta =
            Math.atan2(gd_lat, gd_lon) + 0.000003 * Math.cos(gd_lon * PI)
        bd_lat_lon[0] = z * Math.cos(theta) + 0.0065
        bd_lat_lon[1] = z * Math.sin(theta) + 0.006
        return bd_lat_lon
    }

    /**
     * 去除 最后一个分割 符
     *
     * @param strValue
     * @return
     */
    fun StringTrim(strValue: String): String? {
        var strResult = ""
        strResult = if (TextUtils.isEmpty(strValue)) "" else {
            if (strValue.length <= 1) {
                strValue
            } else {
                strValue.substring(0, strValue.length - 1)
            }
        }
        return strResult
    }

    /**
     * 格式化 m 显示带单位
     *
     * @param strDistance
     * @return
     */
    fun FormatDistance(strDistance: String): String? {
        var strDistance = strDistance
        var strResult = ""
        if (TextUtils.isEmpty(strDistance)) {
            strDistance = "0"
        }
        var d_distance = 0.0
        try {
            d_distance = strDistance.toDouble()
        } catch (e: java.lang.Exception) {
            e.printStackTrace()
        }
        strResult = if (d_distance <= 500) {
            "<500m"
        } else if (d_distance > 500 && d_distance < 1000) {
            d_distance.toString() + "m"
        } else {
            (d_distance / 1000).toString() + "km"
        }
        return strResult
    }

    fun SnapHelper(rlvBase: RecyclerView?) {
        LinearSnapHelper().attachToRecyclerView(rlvBase)
    }

    /**
     * 6 -16
     *
     * @param strPW
     * @return
     */
    fun isPWSize(strPW: String): Boolean {
        if (TextUtils.isEmpty(strPW)) {
            return false
        }
        val pwSize = strPW.length
        return pwSize in 6..16
    }

    fun stringToUnicode(string: String): String? {
        val unicode = StringBuffer()
        for (element in string) { // 取出每一个字符
            val c = element
            // 转换为unicode
//"\\u只是代号，请根据具体所需添加相应的符号"
            unicode.append("\\u" + Integer.toHexString(c.toInt()))
        }
        return unicode.toString()
    }

    fun Call(
        baseContext: Activity,
        str_title: String?,
        str_tel: String?
    ) {
        val dialog = NormalDialog(baseContext)
        dialog.style(NormalDialog.STYLE_TWO)
            .title(str_title).widthScale(0.8f)
            .titleTextColor(Color.parseColor("#000000"))
            .titleTextSize(15f)
            .content(str_tel)
            .contentTextColor(Color.parseColor("#666666"))
            .btnTextSize(15f)
            .btnTextColor(
                Color.parseColor("#007aff"),
                Color.parseColor("#007aff")
            )
            .btnText(
                baseContext.getString(R.string.ignoreNote),
                baseContext.getString(R.string.sure)
            )
            .showAnim(BounceEnter()).dismissAnim(SlideBottomExit()).show()
        dialog.setOnBtnClickL(
            OnBtnClickL {
                //                                    T.showShort(mContext, "left");
                dialog.dismiss()
            },
            OnBtnClickL {
                //                                    T.showShort(mContext, "right");
                //                                    LUtils.showToask(baseContext, "取消！");
                callPhone(baseContext, str_tel!!)
                dialog.dismiss()
            })
    }

    /**
     * 格式化单位
     *
     * @param size size
     * @return size
     */
    fun getFormatSize(size: Double): String? {
        val kiloByte = size / 1024
        if (kiloByte < 1) {
            return size.toString() + "B"
        }
        val megaByte = kiloByte / 1024
        if (megaByte < 1) {
            val result1 =
                BigDecimal(java.lang.Double.toString(kiloByte))
            return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "KB"
        }
        val gigaByte = megaByte / 1024
        if (gigaByte < 1) {
            val result2 =
                BigDecimal(java.lang.Double.toString(megaByte))
            return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "MB"
        }
        val teraBytes = gigaByte / 1024
        if (teraBytes < 1) {
            val result3 =
                BigDecimal(java.lang.Double.toString(gigaByte))
            return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "GB"
        }
        val result4 = BigDecimal(teraBytes)
        return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "TB"
    }

    /**
     * 判断字符串是否乱码
     *
     * @param strName
     * @return boolean
     * @author yang.shen
     */
    fun isMessyCode(strName: String?): Boolean {
        val p = Pattern.compile("\\s*|\t*|\r*|\n*")
        val m = p.matcher(strName)
        val after = m.replaceAll("")
        val temp = after.replace("\\p{P}".toRegex(), "")
        val ch = temp.trim { it <= ' ' }.toCharArray()
        var chLength = 0f
        var count = 0f
        for (i in ch.indices) {
            val c = ch[i]
            if (!Character.isLetterOrDigit(c)) {
                if (!isChinese(c)) {
                    count = count + 1
                }
                chLength++
            }
        }
        val result = count / chLength
        return if (result > 0.4) {
            true
        } else {
            false
        }
    }

    private fun isChinese(c: Char): Boolean {
        val ub = Character.UnicodeBlock.of(c)
        return if (ub === Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub === Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS || ub === Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub === Character.UnicodeBlock.GENERAL_PUNCTUATION || ub === Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub === Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS
        ) {
            true
        } else false
    }

    /**
     * 解析出url参数中的键值对
     * 如 "index.jsp?Action=del&id=123"，解析出Action:del,id:123存入map中
     *
     * @param URL url地址
     * @return url请求参数部分
     */
    fun URLRequest(URL: String): Map<String, String>? {
        val mapRequest: MutableMap<String, String> =
            HashMap()
        var arrSplit: Array<String>? = null
        val strUrlParam = TruncateUrlPage(URL) ?: return mapRequest
        //每个键值为一组 www.2cto.com
        arrSplit = strUrlParam.split("[&]").toTypedArray()
        for (strSplit in arrSplit) {
            var arrSplitEqual: Array<String>? = null
            arrSplitEqual = strSplit.split("[=]").toTypedArray()
            //解析出键值
            if (arrSplitEqual.size > 1) { //正确解析
                mapRequest[arrSplitEqual[0]] = arrSplitEqual[1]
            } else {
                if (arrSplitEqual[0] !== "") { //只有参数没有值，不加入
                    mapRequest[arrSplitEqual[0]] = ""
                }
            }
        }
        return mapRequest
    }

    /**
     * 去掉url中的路径，留下请求参数部分
     *
     * @param strURL url地址
     * @return url请求参数部分
     */
    private fun TruncateUrlPage(strURL: String): String? {
        var strURL = strURL
        if (true) return strURL
        //        支付宝返回的就是参数部分 下边的没啥卵用
        var strAllParam: String? = null
        var arrSplit: Array<String?>? = null
        strURL = strURL.trim { it <= ' ' }
        arrSplit = strURL.split("[?]").toTypedArray()
        if (strURL.length > 1) {
            if (arrSplit.size > 1) {
                if (arrSplit[1] != null) {
                    strAllParam = arrSplit[1]
                }
            }
        }
        return strAllParam
    }

    fun HtmlText(
        ctx: Context,
        tv: TextView,
        str_1: String,
        str_2: String,
        color1: Int,
        color2: Int,
        txtSize1: Int,
        txtSize2: Int
    ) {
        HtmlText(ctx, tv, str_1, str_2, "", color1, color2, 0, txtSize1, txtSize2, 0)
    }

    fun HtmlText(
        ctx: Context,
        tv: TextView,
        str_1: String,
        str_2: String,
        str_3: String,
        color1: Int,
        color2: Int,
        color3: Int,
        txtSize1: Int,
        txtSize2: Int,
        txtSize3: Int
    ) {
        var color1 = color1
        var color2 = color2
        var color3 = color3
        var txtSize1 = txtSize1
        var txtSize2 = txtSize2
        var txtSize3 = txtSize3
        if (color1 == 0) {
            color1 = R.color.base_text
        }
        if (color2 == 0) {
            color2 = R.color.base_text
        }
        if (color3 == 0) {
            color3 = R.color.base_text
        }
        if (txtSize1 == 0) {
            txtSize1 = 18
        }
        if (txtSize2 == 0) {
            txtSize2 = 18
        }
        if (txtSize3 == 0) {
            txtSize3 = 18
        }
        val str = str_1 + str_2 + str_3
        val sp = SpannableStringBuilder(str)
        //        头
        sp.setSpan(
            ForegroundColorSpan(ctx.resources.getColor(color1)),
            0,
            str_1.length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        ) //字体颜色
        sp.setSpan(
            AbsoluteSizeSpan(txtSize1, true),
            0,
            str_1.length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        ) //字体大小
        //身子
//        sp.setSpan(new ForegroundColorSpan(0xFFFF0000), (name1 + name2).length(), str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); //字体颜色
        sp.setSpan(
            ForegroundColorSpan(ctx.resources.getColor(color2)),
            str_1.length,
            (str_1 + str_2).length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        ) //字体颜色
        sp.setSpan(
            AbsoluteSizeSpan(txtSize2, true),
            str_1.length,
            (str_1 + str_2).length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        ) //字体大小
        //        尾巴
        sp.setSpan(
            ForegroundColorSpan(ctx.resources.getColor(color3)),
            (str_1 + str_2).length,
            str.length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        ) //字体颜色
        sp.setSpan(
            AbsoluteSizeSpan(txtSize3, true),
            (str_1 + str_2).length,
            str.length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        ) //字体大小
        //        这个 SpannableStringBuilder 如果转为 tostring 就没有作用了！
        tv.text = sp
    }

    fun HtmlTextItalic(
        ctx: Context,
        tv: TextView,
        str_1: String,
        str_2: String,
        str_3: String,
        color1: Int,
        color2: Int,
        color3: Int,
        txtSize1: Int,
        txtSize2: Int,
        txtSize3: Int
    ) {
        var color1 = color1
        var color2 = color2
        var color3 = color3
        var txtSize1 = txtSize1
        var txtSize2 = txtSize2
        var txtSize3 = txtSize3
        if (color1 == 0) {
            color1 = R.color.base_text
        }
        if (color2 == 0) {
            color2 = R.color.base_text
        }
        if (color3 == 0) {
            color3 = R.color.base_text
        }
        if (txtSize1 == 0) {
            txtSize1 = 18
        }
        if (txtSize2 == 0) {
            txtSize2 = 18
        }
        if (txtSize3 == 0) {
            txtSize3 = 18
        }
        val str = str_1 + str_2 + str_3
        val sp = SpannableStringBuilder(str)
        //        头
        sp.setSpan(
            ForegroundColorSpan(ctx.resources.getColor(color1)),
            0,
            str_1.length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        ) //字体颜色
        sp.setSpan(
            AbsoluteSizeSpan(txtSize1, true),
            0,
            str_1.length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        ) //字体大小
        //身子
//        sp.setSpan(new ForegroundColorSpan(0xFFFF0000), (name1 + name2).length(), str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); //字体颜色
        sp.setSpan(
            ForegroundColorSpan(ctx.resources.getColor(color2)),
            str_1.length,
            (str_1 + str_2).length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        ) //字体颜色
        sp.setSpan(
            AbsoluteSizeSpan(txtSize2, true),
            str_1.length,
            (str_1 + str_2).length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        ) //字体大小
        //        SpannableString spanString = new SpannableString(str);
        val span = StyleSpan(Typeface.ITALIC)
        sp.setSpan(
            span,
            str_1.length,
            (str_1 + str_2).length,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
        ) //字体大小
        //        尾巴
        sp.setSpan(
            ForegroundColorSpan(ctx.resources.getColor(color3)),
            (str_1 + str_2).length,
            str.length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        ) //字体颜色
        sp.setSpan(
            AbsoluteSizeSpan(txtSize3, true),
            (str_1 + str_2).length,
            str.length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        ) //字体大小
        //        这个 SpannableStringBuilder 如果转为 tostring 就没有作用了！
        tv.text = sp
    }

    /**
     * 判断是否是全面屏
     */
    @Volatile
    private var mHasCheckAllScreen = false
    @Volatile
    private var mIsAllScreenDevice = false

    fun isAllScreenDevice(context: Context): Boolean {
        if (mHasCheckAllScreen) {
            return mIsAllScreenDevice
        }
        mHasCheckAllScreen = true
        mIsAllScreenDevice = false
        // 低于 API 21的，都不会是全面屏。。。
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            return false
        }
        val windowManager =
            context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        if (windowManager != null) {
            val display = windowManager.defaultDisplay
            val point = Point()
            display.getRealSize(point)
            val width: Float
            val height: Float
            if (point.x < point.y) {
                width = point.x.toFloat()
                height = point.y.toFloat()
            } else {
                width = point.y.toFloat()
                height = point.x.toFloat()
            }
            if (height / width >= 1.97f) {
                mIsAllScreenDevice = true
            }
        }
        return mIsAllScreenDevice
    }

    /**
     * edittext scrollview  滑动冲突
     *
     * @param etView
     */
    fun SetEditScorll(etView: EditText) {
        etView.setOnTouchListener { v, event ->
            //这句话说的意思告诉父View我自己的事件我自己处理
            v.parent.requestDisallowInterceptTouchEvent(true)
            false
        }
    }

    //设置不可编辑
    fun setEditable(etContent: EditText, isEdit: Boolean) {
        if (isEdit) {
            etContent.isFocusable = true
            etContent.isFocusableInTouchMode = true
        } else {
            etContent.isFocusable = false
            etContent.isFocusableInTouchMode = false
            // 如果之前没设置过点击事件，该处可省略
            etContent.setOnClickListener(null)
        }
    }

    /**
     * 将数据保留两位小数
     */
    fun getTwoDecimal(num: Double): Double {
        val dFormat = DecimalFormat("#0.00")
        val yearString = dFormat.format(num)
        return java.lang.Double.valueOf(yearString)
    }

    /**
     * @param type        1 隐藏 中间  2  隐藏 姓
     * @param strNickName
     * @return
     */
    fun HideName(type: Int, strNickName: String): String? {
        var strNickName = strNickName
        if (!TextUtils.isEmpty(strNickName)) {
            if (type == 1) {
                strNickName = if (strNickName.length <= 3) {
                    strNickName.replace(
                        "*",
                        strNickName.substring(strNickName.length - 1, strNickName.length)
                    )
                } else {
                    strNickName.substring(0, 2) + "*"
                }
            } else if (type == 2) {
                strNickName = if (strNickName.length <= 3) {
                    strNickName.replace("*", strNickName.substring(0, 1))
                } else {
                    strNickName.replace("*", strNickName.substring(0, 2))
                }
            }
        } else {
            strNickName = ""
        }
        return strNickName
    }
}